const axios = require("axios");
const { Sequelize, Model, Op } = require("sequelize");
const { db } = require("../core/db");
const config = require("../config/config");
const util = require("util");
const { Like } = require("./like");
const { encode } = require("punycode");

class Book extends Model {
  async getDetail(id) {
    let url = util.format(config.yushu.detailUrl, id);
    const { data } = await axios.get(url);
    return data;
  }

  static async getSearchList(q, start, count) {
    let url = util.format(
      config.yushu.keywordUrl,
      encodeURIComponent(q),
      count,
      start,
      1
    );
    const { data } = await axios.get(url);
    return data;
  }

  
}
Book.init(
  {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
    },
    fav_nums: {
      type: Sequelize.INTEGER,
      default: 0,
    },
  },
  { sequelize: db, tableName: "book" }
);

module.exports = {
  Book,
};
